<?php

use App\Http\Controllers\ContactController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\NoticeController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// 首页
Route::get('/{typeid?}',[HomeController::class,'index'])->middleware('LoginAuth')->where('typeid','[0-9]+');

// 用户相关路由
Route::prefix('home/user')->group(function(){
    Route::get('index',[UserController::class,'index']);
    Route::get('login',[UserController::class,'login']);
    Route::get('register',[UserController::class,'register']);
});

// 处理表单提交路由
Route::prefix('home')->group(function(){
    Route::post('user/registerform',[UserController::class,'registerform']);
    Route::post('user/loginform',[UserController::class,'loginform']);
    Route::post('user/profileform',[UserController::class,'profileform']);
    Route::post('contact/addform',[ContactController::class,'addform']);
    Route::post('contact/editform',[ContactController::class,'editform']);
});


/**
 *  登录验证的路由
*/
Route::prefix('home')->middleware('LoginAuth')->group(function(){
    Route::get('user/profile',[UserController::class,'profile']);
    Route::get('contact/add',[ContactController::class,'add']);
    Route::get('contact/edit/{contactid}',[ContactController::class,'edit'])->where('contactid','[0-9]+');
});

/**
 * Ajax请求的路由
*/
Route::prefix('home')->group(function(){
    Route::post('user/area',[UserController::class,'area']);
    Route::post('user/logout',[UserController::class,'logout']);
    Route::post('contact/del',[ContactController::class,'del']);
});

/** 
 * 跳转提示路由
*/
Route::any('/success',[NoticeController::class,'success'])->name('success');
Route::any('/error',[NoticeController::class,'error'])->name('error');